package com.webservice.querysta;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.webservice.bean.QueryResult;
import com.webservice.bean.Student;
import com.webservice.bean.StudentPost;
import com.webservice.bean.Teacher;
import com.webservice.store.DataAdapter;

@Path("/query")
public class QueryWeb 
{
	@Context
	ServletContext servletContext;
	
	List<Teacher> querybean=null;
	List<Student> studentbean=null;
	List<StudentPost> studentpostbean=null;
	
	@Path("/viewteacher")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<Teacher> getTeacherDetail(@QueryParam("TeacherID") String TeacherID,@QueryParam("UserType") String UserType)
	{
		
		querybean.addAll(DataAdapter.getTeacherDetail(TeacherID,UserType).values());
		return querybean;
	}
	
	@Path("/viewstudent")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<Student> getStudentDetail(@QueryParam("StudentID") String StudentID,@QueryParam("UserType") String UserType)
	{
		studentbean =new ArrayList<Student>();
		studentbean.addAll(DataAdapter.getStudentDetail(StudentID, UserType).values());
		return studentbean;		
	}
	
	@Path("/viewstudentpost")	
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<StudentPost> getStudentPostDetail(@QueryParam("TeacherID") String TeacherID,@QueryParam("UserType") String UserType)
	{
		studentpostbean =new ArrayList<StudentPost>();
		studentpostbean.addAll(DataAdapter.getStudentPostDetail(TeacherID, UserType).values());
		return studentpostbean;		
	}
	
	@Path("/add")
	@GET
	@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
	public List<QueryResult> InsertUser(@QueryParam("PostedStudentID") String PostedStudentID,
	@QueryParam("StudentPostedTeacherID") String StudentPostedTeacherID,@QueryParam("StudentQuestion") String StudentQuestion,
	@QueryParam("StudentQuestionType") String StudentQuestionType,@QueryParam("UserType") String UserType) 
	{			
		List<QueryResult> Queryresult = null ;		
		Queryresult = new ArrayList<QueryResult>();
		DataAdapter.PostedStudentID=PostedStudentID;
		
		DataAdapter.StudentQuestionType=StudentQuestionType;
		Queryresult.addAll(DataAdapter.getStudentQueriesStatus(UserType).values() );
		return Queryresult;
	}
}
